package com.leetcode.Offer;

public class JZ22 {
    public ListNode getKthFromEnd(ListNode head, int k) {

        //思路：使两个指针间隔k个节点

        ListNode a = head;
        ListNode b = head;
        for (int i = 0; i < k - 1; i++) {
            if (a.next == null) {
                return null;
            } else {
                a = a.next;
            }
        }
        while (a.next != null) {
            a = a.next;
            b = b.next;
        }
        return b;
    }
}
